<!doctype html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4">

<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
<h1>首页</h1>
<hr>
<form th:action="@{/toLevel1}">

    <input type="submit" value="level1">
</form>
<hr>
<div sec:authorize="!isAuthenticated()">
    <a th:href="@{/login}"><h2>登录</h2></a>
</div>
<hr>
<div sec:authorize="isAuthenticated()">
    <a th:href="@{/logout}"><h2>注销</h2></a>
</div>
<hr>

<div sec:authorize="isAuthenticated()">
    <a>
        用户名：<span sec:authentication="name"></span>
        角色：<span sec:authentication="principal.getAuthorities()"></span>
    </a>
</div>
<hr>
<form th:action="@{/logout}">

    <input type="submit" value="注销">
</form>

<hr>
<a th:href="@{/toLevel2}">level2</a>
<hr>
<a href="/toLevel3">level3</a>


</body>
</html>